package b4.scene.load
{
	import b4.net.*;
	import b4.scene.basic.*;
	import b4.util.profile.*;
	import b4.widget.basic.*;
	
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;

	public class MainLoadScene extends BasicScene
	{
		private var loadBar:MaskProgressBar;
		private var loadText:TextField;
		
		public function MainLoadScene(resourceLoader:ResourceLoader)
		{
			//主背景
			var mainBgrSprite:BasicWidget = new BasicWidget();
			mainBgrSprite.anchor = BasicWidget.ANCHOR_MIDDLE_MIDDLE;
			mainBgrSprite.addChild(new MainLoadBgr());
			mainBgrSprite.x = -mainBgrSprite.width / 2;
			mainBgrSprite.y = -mainBgrSprite.height / 2;
			addChild(mainBgrSprite);
			//LOGO
			var logoSprite:BasicWidget = new BasicWidget();
			logoSprite.anchor = BasicWidget.ANCHOR_MIDDLE_MIDDLE;
			logoSprite.addChild(new MainLogo());
			logoSprite.x = -logoSprite.width / 2;
			logoSprite.y = -150;
			addChild(logoSprite);
			//进度条
			loadBar = new MaskProgressBar(MainProcessBar, MainProcessBarBgr);
			loadBar.x = (GameProfile.stageWidth - loadBar.width) / 2;
			loadBar.y = 400;
			addChild(loadBar);
			//文字
			loadText = new TextField();
        	loadText.autoSize = TextFieldAutoSize.CENTER;
			loadText.defaultTextFormat = new TextFormat("微软雅黑", 16, 0xFFFFFF);
			loadText.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			loadText.selectable = false;
			loadText.x = GameProfile.stageWidth / 2;
			loadText.y = 350;
			addChild(loadText);
			resourceLoader.addEventListener(ProgressEvent.PROGRESS, onResourceProgress);
		}

		private function onResourceProgress(event:ProgressEvent):void
		{
			var resourceLoader:ResourceLoader = event.currentTarget as ResourceLoader;
	    	loadBar.percentage = event.bytesLoaded / event.bytesTotal;
	    	var currentResourceIndex:int = resourceLoader.urlIndex + 1;
	    	var totolResourceNum:int = resourceLoader.urlNames.length;
	    	loadText.text = "正在加载资源 " + currentResourceIndex + "/" + totolResourceNum;
		}
	}
}